var userTree = function(combo) {
	userTree.superclass.constructor.call(this, {
				id : 'deptTree',
				animate : true,
				enableDD : false,
				rootVisible : false,
				border : false,
				root : new Ext.tree.AsyncTreeNode({
							expanded : false,
							text : "组织结构"
						}),
				loader : tl = new Ext.tree.TreeLoader({
							url : '../script/it-networkmaster/data/tree.txt'
						}),
				listeners : {
					"click" : function(node, event) {
						var val = node.id;
						if (val.indexOf('dep') < 0) {// 判断叶子节点为部门时，不允许选择
							if (node.leaf) {// 员工为叶子时，给combo、userId赋值
								combo.setValue(node.text);
								//Ext.getCmp('userId').setValue(node.id);
								combo.collapse();
							} else {
								node.toggle();
							}
						}
					}
				}
			});
};
Ext.extend(userTree, Ext.tree.TreePanel);// userTree继承Ext.tree.TreePanel
// -----定义树型下拉框类-----------------
var userComboBox = function(label, wid, eText, bText) {
	var user = this;
	userComboBox.superclass.constructor.call(this, {
		id : 'userCombo',
		isFormField : true,
		valueField : "value",
		displayField : "text",
		fieldLabel : label,
		emptyText : eText,
		width : wid,
		store : new Ext.data.SimpleStore({
					fields : [],
					data : [[]]
				}),
		editable : false,
		allowBlank : false,
		blankText : bText,
		mode : 'local',
		triggerAction : 'all',
		tpl : "<tpl for='.'><div style='height:200px'><div id='deptUser'></div><div></tpl>",
		listeners : {
			"expand" : function() {                                  //当combobox展开时触发expand时间然后回调构造treepanel
				(new userTree(user)).render('deptUser');
			},
			"collapse" : function() {
				document.getElementById('deptUser').innerHTML = "";
			}
		}
	});
};
Ext.extend(userComboBox, Ext.form.ComboBox);// userComboBox继承Ext.form.ComboBox

Ext.onReady(function() {

			var p = new Ext.Panel({
                layout:"form",
						title : "test",
						width : 200,
						height : 450,
                        labelWidth:40,
						items : [new userComboBox("树", 100, "etext", "btext")]
					});
			p.render(Ext.getBody());
		})
